07. Composition of Rotations

Composition of Rotations

Composition Of Rotations

The interested reader can explore the derivation of the composition rules here.

Although Euler angles and rotation matrices are relatively intuitive, they do suffer from two significant drawbacks. First, are issues related to numerical performance. Defining the orientation of a rigid body in a three-dimensional environment only requires three generalized coordinates; however, rotation matrices contain nine elements. Clearly not all nine elements are independent and more memory is required to capture the orientation information than is required using a minimal set.

Rotation matrices are also not very numerically stable. Rounding errors associated with the repeated multiplication of rotation matrices also creates numerical drift. This means that over time the orthonormality conditions can be violated and the matrix will no longer be a valid rotation matrix. Also, it is a non-trivial task to interpolate smoothly between two rotation matrices (this is particularly important for computer animations when trying to generate smooth motions between key frames).

The second significant drawback is singularities of representation (not to be confused with kinematic singularities). Singularities of representation occur when the second rotation in the sequence is such that the first and third coordinate frames become aligned causing a loss of a degree of freedom. This condition is often called "gimbal lock". In the case of the Z-Y-X rotation sequence used in Eq (4), observe what happens to the overall rotation matrix when \beta = \pi/2.

\mathbf{_{B}^{A}\textrm{R}_{ZYX} = \begin{bmatrix} 1 & 0 & 0\\ 0 & c_{\gamma} & -s_{\gamma}\\ 0 & s_{\gamma} & c_{\gamma} \end{bmatrix} \begin{bmatrix} c_{\pi/2} & 0 & s_{\pi/2}\\ 0 & 1 & 0\\ -s_{\pi/2} & 0 & c_{\pi/2} \end{bmatrix} \begin{bmatrix} c_{\alpha} & -s_{\alpha} & 0\\ s_{\alpha} & c_{\alpha} & 0\\ 0 & 0 & 1 \end{bmatrix} }
\mathbf{_{B}^{A}\textrm{R}_{ZYX} = \begin{bmatrix} 1 & 0 & 0\\ 0 & c_{\gamma} & -s_{\gamma}\\ 0 & s_{\gamma} & c_{\gamma} \end{bmatrix} \begin{bmatrix} 0 & 0 & 1\\ 0 & 1 & 0\\ -1 & 0 & 0 \end{bmatrix} \begin{bmatrix} c_{\alpha} & -s_{\alpha} & 0\\ s_{\alpha} & c_{\alpha} & 0\\ 0 & 0 & 1 \end{bmatrix} }
\mathbf{_{B}^{A}\textrm{R}_{ZYX} = \begin{bmatrix} 0 & 0 & 1\\ s_{\gamma} & c_{\gamma} & 0\\ -c_{\gamma} & s_{\gamma} & 0 \end{bmatrix} \begin{bmatrix} c_{\alpha} & -s_{\alpha} & 0\\ s_{\alpha} & c_{\alpha} & 0\\ 0 & 0 & 1 \end{bmatrix} }
\mathbf{_{B}^{A}\textrm{R}_{ZYX} = \begin{bmatrix} 0 & 0 & 1\\ s_{\alpha+\gamma} & s_{\alpha+\gamma} & 0\\ -c_{\alpha+\gamma} & s_{\alpha+\gamma} & 0 \end{bmatrix} }

Notice that no matter what the angles alpha and gamma may be, they have no effect on the X component. It is important to note that there is nothing wrong or physically inhibiting rotational motion, it is rather a mathematical deficiency in the choice of representing rotational motions. Further, ALL conventions using only three parameters to describe orientation suffer from singularities of representation. Therefore, a key consideration to using Euler angles in practice is to ensure that the range of motion of the object of interest does not come close to a singularity.

Just for fun:

** Coding Quizzes **

Two coding quizzes follow. The first requires you to perform an intrinsic rotation sequence about the Y and then Z axes. The second quiz requires you to perform an extrinsic rotation about the Z and then Y axes.

Start Quiz:

from sympy import symbols, cos, sin, pi, sqrt
from sympy.matrices import Matrix

### Create symbols for joint variables
q1, q2 = symbols('q1:3')

# Create a symbolic matrix representing an intrinsic sequence of rotations 
  # about the Y and then Z axes. Let the rotation about the Y axis be described
  # by q1 and the rotation about Z by q2. 
####### TO DO ########
# Replace R_y and R_z with the appropriate (symbolic) elementary rotation matrices 
  # and then compute YZ_intrinsic. 
R_y = 1
R_z = 1
YZ_intrinsic_sym = 1

####### TO DO ########
# Numerically evaluate YZ_intrinsic assuming:
   # q1 = 45 degrees and q2 = 60 degrees. 
   # NOTE: Trigonometric functions in Python assume the input is in radians!  

YZ_intrinsic_num = 1 #YZ_intrinsic_sym.evalf(subs={})
from sympy import symbols, cos, sin, pi, sqrt
from sympy.matrices import Matrix

### Create symbols for joint variables
q1, q2 = symbols('q1:3')

# Create a symbolic matrix representing an intrinsic sequence of rotations 
  # about the Y and then Z axes. Let the rotation about the Y axis be described
  # by q1 and the rotation about Z by q2. 
####### TO DO ########
# Replace R_y and R_z with the appropriate (symbolic) elementary rotation matrices 
  # and then compute YZ_intrinsic. 
R_y = Matrix([[ cos(q1),        0, sin(q1)],
              [ 0,              1,       0],
              [-sin(q1),        0, cos(q1)]])
R_z = Matrix([[ cos(q2), -sin(q2),       0],
              [ sin(q2),  cos(q2),       0],
              [       0,        0,       1]])

YZ_intrinsic_sym = R_y * R_z
YZ_intrinsic_num = YZ_intrinsic_sym.evalf(subs={q1: pi/4, q2: pi/3})

Start Quiz:

from sympy import symbols, cos, sin, pi, sqrt
from sympy.matrices import Matrix

### Create symbols for joint variables
q1, q2 = symbols('q1:3')

# Create a symbolic matrix representing an extrinsic sequence of rotations 
  # about the Z and then Y axes. Let the rotation about the Y axis be described
  # by q1 and the rotation about Z by q2. 
####### TO DO ########
# Replace R_y and R_z with the appropriate (symbolic) elementary rotation matrices 
  # and then compute ZY_extrinsic. 
R_y = 1
R_z = 1
ZY_extrinsic_sym = 1
ZY_extrinsic_num = 1

####### TO DO ########
# Numerically evaluate ZY_extrinsic assuming:
   # q1 = 45 degrees and q2 = 60 degrees. 
   # NOTE: Trigonometric functions in Python assume the input is in radians!  
#ZY_extrinsic_sym = 
#ZY_extrinsic_num = ZY_extrinsic_sym.evalf(subs{})
from sympy import symbols, cos, sin, pi, sqrt
from sympy.matrices import Matrix

### Create symbols for joint variables
q1, q2 = symbols('q1:3')

# Create a symbolic matrix representing an extrinsic sequence of rotations 
  # about the Z and then Y axes. Let the rotation about the Y axis be described
  # by q1 and the rotation about Z by q2. 
####### TO DO ########
# Replace R_y and R_z with the appropriate (symbolic) elementary rotation matrices 
  # and then compute ZY_extrinsic. 
R_y = Matrix([[ cos(q1),        0, sin(q1)],
              [ 0,              1,       0],
              [-sin(q1),        0, cos(q1)]])
R_z = Matrix([[ cos(q2), -sin(q2),       0],
              [ sin(q2),  cos(q2),       0],
              [       0,        0,       1]])
ZY_extrinsic_sym = R_y * R_z
ZY_extrinsic_num = ZY_extrinsic_sym.evalf(subs={q1: pi/4, q2: pi/3})

Did You Notice?

Did you notice anything interesting about the results of the last two quizzes?

SOLUTION: Yes, an extrinsic rotation sequence of A, B, C is equal to an intrinsic rotation sequence C, B, A.